from rest_framework import serializers
from news import models

class SerNews(serializers.ModelSerializer):
    class Meta:
        model = models.News
        fields = '__all__'


# def ming(value):
#     data = models.User.objects.filter(name=value).first()
#     if data:
#         raise serializers.ValidationError("该用户名已经被注册")


class SerUser(serializers.ModelSerializer):
    class Meta:
        model = models.User
        fields = '__all__'


class SerMessage(serializers.ModelSerializer):
    user = serializers.SerializerMethodField(read_only=True)
    def get_user(self,obj):
        return {"name": obj.uname.name}
    class Meta:
        model = models.Messgae
        fields = '__all__'